package com.tang.service;
import com.tang.pojo.Page;
import com.tang.Dao.PageDao;
import com.tang.pojo.Book;
import org.apache.commons.beanutils.BeanUtils;
import java.util.Map;
import java.util.List;
public class PageServiceImpl implements PageService{
    @Override
    public Page getPage(int pageNow, int pageSize) {
        PageDao pd=new PageDao();
        int countTotal=pd.calCountTotal();
        List<Book> items=pd.calitems(pageNow,pageSize);
        int pageTotal=0;
        if(countTotal%pageSize==0){
            pageTotal=countTotal/pageSize;
        }else{
            pageTotal=countTotal/pageSize+1;
        }
       return new Page(pageNow,pageSize,pageTotal,countTotal,items);
    }

    @Override
    public Page getPageByPrice(int pageNow, int pageSize,int begin,int end) {
        PageDao pd=new PageDao();
        int countTotal=pd.calCountTotalByPrice(begin,end);
        List<Book> items=pd.calitemsByPrice(pageNow,pageSize,begin,end);
        int pageTotal=0;
        if(countTotal%pageSize==0){
            pageTotal=countTotal/pageSize;
        }else{
            pageTotal=countTotal/pageSize+1;
        }
        return new Page(pageNow,pageSize,pageTotal,countTotal,items);
    }
}
